using System.Linq;
using Magiq.Databases;
using Magiq.Tests.Support;
using NUnit.Framework;

namespace Magiq.Tests
{
    [TestFixture]
    public class SelectColumnExpressionParserTests
    {
        private readonly SelectColumnExpressionParser Parser = new SelectColumnExpressionParser();

        [Test]
        public void ShouldSplitCommaDelimitedValues()
        {
            var values = Parser.Parse("bla,ble,bli").ToArray();
            values.Should(Have.Length(3));
            values[0].Should(Be.EqualTo("bla"));
            values[1].Should(Be.EqualTo("ble"));
            values[2].Should(Be.EqualTo("bli"));
        }

        [Test]
        public void ShouldNotSplitACommaUsedInsideParenthesis()
        {
            var values = Parser.Parse("bla,(ble,bli)").ToArray();
            values.Should(Have.Length(2));
            values[0].Should(Be.EqualTo("bla"));
            values[1].Should(Be.EqualTo("(ble,bli)"));
        }

        [Test]
        public void ShouldNotSplitACommaUsedInsideSquareParenthesis()
        {
            var values = Parser.Parse("bla,[ble,bli]").ToArray();
            values.Should(Have.Length(2));
            values[0].Should(Be.EqualTo("bla"));
            values[1].Should(Be.EqualTo("[ble,bli]"));
        }

        [Test]
        public void ShouldSupportDeepParenthesisUsage()
        {
            var values = Parser.Parse("bla,((ble,bli),blo),blu").ToArray();
            values.Should(Have.Length(3));
            values[0].Should(Be.EqualTo("bla"));
            values[1].Should(Be.EqualTo("((ble,bli),blo)"));
            values[2].Should(Be.EqualTo("blu"));
        }

        [Test]
        public void ShouldNotSplitACommaUsedInsideQuotationMarks()
        {
            var values = Parser.Parse("bla,\"ble,bli\"").ToArray();
            values.Should(Have.Length(2));
            values[0].Should(Be.EqualTo("bla"));
            values[1].Should(Be.EqualTo("\"ble,bli\""));
        }
    }
}